<template>
  <div id="app">
    <!-- 顶部组件 -->
    <header-nav></header-nav>
    <!-- 轮播图 -->
    <div class="banner">
      <div class="imgs">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="(item, index) in imgs" :key="index">
            <img :src="item.pic" />
          </van-swipe-item>
        </van-swipe>
      </div>
    </div>
    <!-- 推荐歌单 -->
    <div class="remLists">
      <div class="remLists-title">
        <div class="title">推荐歌单</div>
        <router-link tag="div" to="/recommendcon" class="more"
          >更多</router-link
        >
      </div>

      <div class="content">
        <!-- 轮播图 -->
        <div class="swiper-container-02">
          <div class="swiper-wrapper">
            <div
              class="swiper-slide item"
              v-for="(item, index) in title"
              :key="index"
            >
              <router-link
                tag="div"
                :to="'/rank/ranklist?id=' + item.id"
                class="img"
              >
                <img :src="item.picUrl" alt="" />
              </router-link>
              <p>{{ item.name }}</p>
              <span
                ><i class="iconfont icon-erji1"></i
                >{{ item.playCount | playCountData }}</span
              >
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 推荐新音乐 -->
    <div class="remLists">
      <div class="remLists-title">
        <div class="title">推荐新音乐</div>
        <router-link tag="div" to="/personalized" class="more"
          >更多</router-link
        >
      </div>

      <div class="content">
        <!-- 轮播图 -->
        <div class="swiper-container-02">
          <div class="swiper-wrapper">
            <div
              class="swiper-slide item"
              v-for="(item, index) in itemnew"
              :key="index"
              @click="xinsetId(item.id)"
            >
              <div class="img">
                <img :src="item.picUrl" alt="" />
              </div>
              <p>{{ item.name }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 推荐MV -->
    <div class="remLists bottons">
      <div class="remLists-title">
        <div class="title">推荐MV</div>
        <router-link tag="div" to="/mvscon" class="more">更多</router-link>
      </div>

      <div class="content">
        <!-- 轮播图 -->
        <div class="swiper-container-03">
          <div class="swiper-wrapper">
            <router-link
              class="swiper-slide item"
              v-for="(item, index) in mvement"
              :key="index"
              tag="div"
              :to="'/mvsublist?id=' + item.id"
            >
              <div class="mvimg">
                <img :src="item.cover" alt="" />
              </div>
              <p>{{ item.name }}</p>
            </router-link>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Swiper from "swiper";
import headerNav from "../components/base/headerNav.vue";
import { getBanner } from "../api/recommend";
import { getPersonalizedr } from "../api/recommend";
import { getpersonalized } from "../api/personalized";
import { getPersonalizedDjprogram } from "../api/personalizeddjprogram";
import { getMvAll } from "../api/userinfo";
export default {
  components: {
    headerNav,
  },
  data: function () {
    return {
      imgs: null,
      title: null,
      itemnew: null,
      titlenew: null, //电台
      mvement: null, //mv列表
    };
  },
  methods: {
    setId(id) {
      // 播放全部歌曲
      this.$emit("get-play-all-id", id); //专递歌单id
      this.$emit("get-player-id", id);
    },
    xinsetId(id){
      // 播放单曲
      this.$emit("get-player-id", id);
    }
  },
  created() {
    //获取轮播图数据
    getBanner().then((data) => {
      this.imgs = data.banners;
    });
    //获取歌单数据
    getPersonalizedr().then((data) => {
      this.title = data.result;
    });
    //获取新音乐数据
    getpersonalized().then((data) => {
      this.itemnew = data.result;
    });
    //获取电台数据
    getPersonalizedDjprogram().then((data) => {
      console.log(data);
      this.titlenew = data.result;
    });
    //获取mv数据
    getMvAll({limit:6}).then((data) => {
      console.log(data.data);
      this.mvement = data.data;
    });
  },
  mounted() {
    new Swiper(".swiper-container-02", {
      pagination: ".swiper-pagination-02",
      slidesPerView: 3,
      paginationClickable: true,
      observer: true,
      observeParents: true,
      spaceBetween: 30,
    });
    new Swiper(".swiper-container-03", {
      pagination: ".swiper-pagination-03",
      slidesPerView: 2,
      paginationClickable: true,
      observer: true,
      observeParents: true,
      spaceBetween: 30,
    });
  },
  filters: {
    playCountData(value) {
      let w = value > 10000 ? value / 10000 : value; //万计算
      let y = w > 10000 ? parseInt(value / 10000) + "亿" : parseInt(w) + "万";
      return y;
    },
  },
};
</script>

<style lang="less">
.swiper-container-02 {
  max-width: 375px;
  overflow: hidden;
  span {
    position: absolute;
    top: 0;
    right: 0;
    color: #fff;
    font-size: 10px;
  }
  i {
    font-size: 15px;
    vertical-align: middle;
  }
  .img {
    min-height: 50px;
    width: 100%;
    border-radius: 3px;
    img {
      width: 100%;
      border-radius: 3px;
    }
  }
  p {
    font-size: 12px;
    color: #565658;
    line-height: 15px;
    padding: 5px;
    margin-bottom: 10px;
    height: 24px;
    overflow: hidden;
  }
}
.swiper-container-03 {
  max-width: 375px;
  overflow: hidden;
  span {
    position: absolute;
    top: 0;
    right: 0;
    color: #fff;
    font-size: 10px;
  }
  i {
    font-size: 15px;
    vertical-align: middle;
  }
  .img {
    min-height: 50px;
    width: 100%;
    border-radius: 3px;
    img {
      width: 100%;
      border-radius: 3px;
    }
  }
  p {
    font-size: 12px;
    color: #565658;
    line-height: 15px;
    padding: 5px;
    margin-bottom: 10px;
    height: 24px;
    overflow: hidden;
  }
}
.banner {
  &::before {
    position: relative;
    content: "";
    display: block;
    height: 124px;
    background-color: #d44439;
    position: absolute;
    width: 375px;
    z-index: -1;
  }
  .imgs {
    position: relative;
    left: 0;
    right: 0;
    top: 0;
    margin: auto;
    width: 96%;
    border-radius: 4px;
    overflow: hidden;
    img {
      width: 100%;
    }
  }
}

.remLists {
  .remLists-title {
    display: flex;
    justify-content: space-between;
    .title {
      height: 60px;
      line-height: 60px;
      text-indent: 5px;
      font-size: 16px;
      color: #000;
      font-weight: bold;
    }
    .more {
      height: 60px;
      line-height: 60px;
      text-indent: 5px;
      font-size: 14px;
      color: rgb(122, 120, 120);
      position: relative;
      right: 10px;
    }
  }
  .content {
    .item {
      position: relative;
      .img {
        width: 120px;
        height: 120px;
        margin: 5px;
        border-radius: 5px;
        img {
          width: 100%;
          height: 100%;
          border-radius: 5px;
        }
      }
      .mvimg {
        width: 180px;
        height: 100px;
        margin: 5px;
        border-radius: 5px;
        img {
          width: 100%;
          height: 100%;
          border-radius: 5px;
        }
      }
      span {
        position: absolute;
        right: -15px;
        top: 7px;
      }
      p {
        font-size: 12px;
        color: #565658;
        line-height: 15px;
        padding: 5px;
        margin-bottom: 10px;
        height: 10px;
        overflow: hidden;
      }
    }
  }
}
.bottons {
  padding-bottom: 50px;
}
</style>